package LearnAlgorithm.c_递归and查找排序;

/*
给定已排序数组arr和k ,不重复打印arr中所有相加和为k的不降序二元组
如输入arr={-8,-4,-3,0,2,4,5,8,9,10},k=10
输出
(0,10)
(2,8)
 */
public class q有序数组中找和的因子 {
	public static void main(String[] args) {
		int[] arr = new int[] {-8,-4,-3,0,2,4,5,8,9,10};
		findSumOfTwo(arr, 0, arr.length - 1, 10);
	}
	
	public static void findSumOfTwo(int[] arr, int p, int r, int k) {
		while (p < r) {
			if (arr[p] + arr[r] == k) {
				System.out.println("(" + arr[p] + "," + arr[r] + ")");
				p++;
				r--;
			} else if (arr[p] + arr[r] < k) {
				p++;
			} else if (arr[p] + arr[r] > k) {
				r--;
			}
		}
	}
}
